package com.baor.service.impl;

import com.baor.base.util.R;
import com.baor.domain.MovieVO;
import com.baor.feign.MovieManagerFeign;
import com.baor.service.SMovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class SMovieServiceImpl implements SMovieService {

    @Autowired
    private MovieManagerFeign movieManagerFeign;

    @Override
    public R movieList(Map<String,Object> params) {
//        String r = this.movieManagerFeign.movieList(params);
//        System.out.println(r);
//        return r;
        R r = this.movieManagerFeign.movieList(params);
        Map<String,Object> dataset = (Map<String, Object>) r.get("dataset");
        List<LinkedHashMap<String,Object>> movieList = (List<LinkedHashMap<String, Object>>) dataset.get("movieList");
        List<String> collect = movieList.stream().map(x -> x.get("movieName").toString()).collect(Collectors.toList());
        return R.ok(collect);
    }

    @Override
    public R movieInfo() {
        MovieVO movieVO = this.movieManagerFeign.movieInfo(1);
        return R.ok(movieVO);
    }
}
